package com.asion.qkan.ui.view;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.asion.qkan.R;
import com.asion.qkan.adapters.HomeVPAdapter;
import com.asion.qkan.ui.fragment.AllContentFragment;
import com.asion.qkan.ui.fragment.DescriptionFragment;
import com.asion.qkan.utils.changeTheme.ThemeChangeUtil;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AllActivity extends AppCompatActivity {

    @BindView(R.id.all_cover_image)
    SimpleDraweeView allCoverImage;
    @BindView(R.id.all_toolbar)
    Toolbar allToolbar;
    @BindView(R.id.activity_all)
    CoordinatorLayout activityAll;
    @BindView(R.id.all_tab)
    TabLayout allTab;
    @BindView(R.id.all_viewpager)
    ViewPager allViewpager;

    private List<Fragment> listFragments = new ArrayList<>();
    private String[] titles = {"简介","内容"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeChangeUtil.changeTheme(this);
        setContentView(R.layout.activity_all);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        Bundle extras = intent.getBundleExtra("bundle");
        //请求网络需要的网址
        String id = extras.getString("id");

        String title = extras.getString("title");
        setTitle(title);

        String vertical_image_url = extras.getString("vertical_image_url");
        Uri parse = Uri.parse(vertical_image_url);
        allCoverImage.setImageURI(parse);

        setSupportActionBar(allToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        DescriptionFragment dsFragment = new DescriptionFragment();
        dsFragment.setArguments(extras);
        AllContentFragment allContentFragment = new AllContentFragment();
        allContentFragment.setArguments(extras);
        listFragments.add(dsFragment);
        listFragments.add(allContentFragment);
        allTab.setupWithViewPager(allViewpager);
        allViewpager.setAdapter(new HomeVPAdapter(getSupportFragmentManager(),listFragments,titles));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_focus:
                break;
            case android.R.id.home:
                finish();
                break;
        }
        return true;
    }
    public static void startAction(Activity activity, Bundle bundle) {
        Intent intent = new Intent(activity, AllActivity.class);
        intent.putExtra("bundle", bundle);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.fade_in,
                R.anim.fade_out);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.all_menu, menu);
        return true;
    }


}
